package com.auxgroup.smarthome.inner.repo;

import com.auxgroup.smarthome.inner.entity.AppUserEntity;
import com.auxgroup.smarthome.repo.GenericDao;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by kevinchen on 2017/3/23.
 */
public interface AppUserEntityRepo extends GenericDao<AppUserEntity, String> {

    AppUserEntity findByUid(String uid);

    /**
     * 根据用户的性别 与 城市 查找用户
     * @param gender
     * @param city
     * @return
     */
    List<AppUserEntity> findByGenderAndAndCity(String gender,String city);

    /**
     * 根据城市来查找用户
     * @param city
     * @return
     */
    List<AppUserEntity> findByCity(String city);

    /**
     * 根据性别来查找用户
     * @param gender
     * @return
     */
    List<AppUserEntity> findByGender(String gender);

    @Modifying
    @Query("update AppUserEntity o set o.openid=?1,o.qqid=?2,o.phone=?3 where o.uid=?4")
    @Transactional(readOnly = false)
    int bindOtherAccount(String openid,String qqid,String phone,String uid);

    List<AppUserEntity> findByOpenid(String openid);

    List<AppUserEntity> findByQqid(String qqid);

    AppUserEntity findByPhoneAndOpenidIsNullAndQqidIsNull(String phone);

    List<AppUserEntity> findByOpenidIsNullAndQqidIsNull();

}
